package com.seal.tsms.other.entity;

import com.seal.tsms.base.entity.BaseEntity;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

/**
 * Created by seal on 2016/3/20.
 */
@Entity
@Table(name="other_subject")
public class Subject extends BaseEntity{

    private String content;
    private String state;
    private Token token;
    private Set<Reply> replies=new HashSet<>();
    private Set<Vote> votes=new HashSet<>();

    @Column(name = "subject_content")
    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    @Column(name = "subject_state")
    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    @ManyToOne
    @JoinColumn(name = "token_id")
    public Token getToken() {
        return token;
    }

    public void setToken(Token token) {
        this.token = token;
    }

    @OneToMany(cascade = CascadeType.ALL,mappedBy = "subject")
    public Set<Reply> getReplies() {
        return replies;
    }

    public void setReplies(Set<Reply> replies) {
        this.replies = replies;
    }

    @OneToMany(cascade = CascadeType.ALL,mappedBy = "subject")
    public Set<Vote> getVotes() {
        return votes;
    }

    @Transient
    public int getVoteCount(){
        return votes.size();
    }
    public void setVotes(Set<Vote> votes) {
        this.votes = votes;
    }
}
